<?php 
namespace Home\Controller;
use Think\Controller;

class PersonalController extends Controller
{
	public function index()
	{
		layout('layout/layout');
		$list = M('user')->select();
		$data = M('user')->find($id);
		// var_dump($list);
		// exit;
		$id=I('get.id/d');
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->display('Personal/index');
	}

	//文件上传
	public function upload()
	{
		$upload = new \Think\Upload();
		$upload->maxSize = 9999999;
		$upload->rootPath='./Public';
		$upload->exts    = array('jpg','gif','png','jpeg');
		$upload->savePath= '/Uploads/';
		$info = $upload->uploadOne($_FILES['photo']);
		// var_dump($info);
		// exit;
		if(!$info){
			$this->error($upload->getError());
		   }
		// }else{
		// 	echo $info['savepath'].$info['savename'];
		// }
		$model = M('user');
		$data['photo'] = $info['savepath'].$info['savename'];
		$data['create_time'] = NOW_TIME;
		$data['id'] = 1;
		if($model->save($data)>0){
			$this -> redirect('index');
		}else{
			$this -> error($model->getError(),'index');
		}
		
		
		// $this->display('Personal/index');
	}
	//修改个人中心
	public function update()
	{
    	M('user')->create();
          
        if (M('user')->save() > 0) {
            $this->success('恭喜您,保存成功!',U('index'));
        } else {
            $this->error('保存失败!');
        }
    }
	
	
}
